package com.ptp.backendcertms.business.controller;

import com.ptp.backendcertms.api.external.dto.req.*;
import com.ptp.backendcertms.api.external.dto.res.ReportDetailResDto;
import com.ptp.backendcertms.api.external.dto.res.ReportListResDto;
import com.ptp.backendcertms.api.external.dto.res.ResponseDto;
import com.ptp.backendcertms.api.external.dto.res.ResponseEmptyDto;
import com.ptp.backendcertms.basiccompnents.http.ResponseWrapper;
import com.ptp.backendcertms.business.service.IReportBusinessService;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 报告业务控制器
 *
 * @author songcongcong
 * @date 2025/5/5
 */
@RestController
@RequestMapping("/cms")
public class ReportBusinessController {
    @Resource
    private IReportBusinessService reportBusinessService;

    /**
     * 证书列表查询
     *
     * @param reqDto 请求参
     */
    @RequestMapping(value = "/report/queryList", method = RequestMethod.POST)
    public ResponseDto<ReportListResDto> getReportList(@RequestBody @Valid ReportListReqDto reqDto, BindingResult bindingResult) {
        return ResponseWrapper.responseReturnWithValid(bindingResult, "[报告管理]-报告列表查询",
                () -> reportBusinessService.getReportList(reqDto));
    }

    /**
     * 证书详情查询
     *
     * @param reqDto 请求参
     */
    @RequestMapping(value = "/report/queryDetail", method = RequestMethod.POST)
    public ResponseDto<ReportDetailResDto> getReportDetail(@RequestBody @Valid ReportDetailReqDto reqDto, BindingResult bindingResult) {
        return ResponseWrapper.responseReturnWithValid(bindingResult, "[报告管理]-报告详情查询",
                () -> reportBusinessService.getReportDetail(reqDto));
    }


    /**
     * 报告删除接口
     */
    @RequestMapping(value = "/report/delete", method = RequestMethod.POST)
    public ResponseEmptyDto delete(@RequestBody @Valid ReportDeleteReqDto reqDto, BindingResult bindingResult) {
        return ResponseWrapper.responseWithValid(bindingResult, "[报告管理]-删除报告", () ->
                reportBusinessService.deleteReport(reqDto));
    }

    /**
     * 报告编辑接口
     */
    @RequestMapping(value = "/report/update", method = RequestMethod.POST)
    public ResponseEmptyDto update(@RequestBody @Valid ReportUpdateReqDto reqDto, BindingResult bindingResult) {
        return ResponseWrapper.responseWithValid(bindingResult, "[报告管理]-编辑报告", () ->
                reportBusinessService.updateReport(reqDto));
    }

}
